package com.zsk.shop.controller.gop;

import com.zsk.shop.common.annotion.Log;
import com.zsk.shop.common.annotion.NoPermission;
import com.zsk.shop.common.base.BaseResponse;
import com.zsk.shop.common.enums.BusinessType;
import com.zsk.shop.model.params.GopUserAddParams;
import com.zsk.shop.model.params.GopUserEditParams;
import com.zsk.shop.model.params.GopUserLoginParams;
import com.zsk.shop.model.results.GopLoginInfoResult;
import com.zsk.shop.service.GopUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "GOP管理员用户相关")
@RequestMapping("/gop/user")
public class GopUserController {

    @Autowired
    private GopUserService gopUserService;

    @Log(title = "后台登录", businessType = BusinessType.LOGIN)
    @NoPermission
    @ApiOperation("登录")
    @PostMapping("/login.do")
    public BaseResponse<GopLoginInfoResult> login(@RequestBody GopUserLoginParams params) {
        return gopUserService.login(params);
    }

    @PostMapping("/getMenuByMineRoleId.do")
    @ApiOperation("依据角色刷新获取相关用户菜单昵称等信息")
    public BaseResponse<GopLoginInfoResult> getMenuByRoleId() {
        return gopUserService.getMenuByRoleId();
    }

    @GetMapping("/setRoleId.do")
    @ApiOperation("设置用户管理员角色")
    @ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户id"),
            @ApiImplicitParam(name = "roleId", value = "角色id")})
    public BaseResponse setRoleId(Long userId, Long roleId) {
        return gopUserService.setRoleId(userId, roleId);
    }

    @Log(title = "新增管理员", businessType = BusinessType.INSERT)
    @PostMapping("/addGopUser.do")
    @ApiOperation("新增管理员用户")
    public BaseResponse addGopUser(@RequestBody GopUserAddParams params) {
        return gopUserService.addGopUser(params);
    }

    @Log(title = "修改管理员", businessType = BusinessType.UPDATE)
    @PostMapping("/updateGopUser.do")
    @ApiOperation("修改管理员用户")
    public BaseResponse updateGopUser(@RequestBody GopUserEditParams params) {
        return gopUserService.updateGopUser(params);
    }

    @Log(title = "修改管理员密码", businessType = BusinessType.UPDATE)
    @GetMapping("/updateGopUserPwd.do")
    @ApiOperation("修改管理员用户密码")
    @ApiImplicitParams({@ApiImplicitParam(name = "userNo", value = "用户No"),
            @ApiImplicitParam(name = "oldPwd", value = "老密码"),
            @ApiImplicitParam(name = "pwd", value = "新密码")})
    public BaseResponse updateGopUserPwd(String userNo, String oldPwd, String pwd) {
        return gopUserService.updateGopUserPwd(userNo, pwd, oldPwd);
    }

    @PostMapping("/gopUserList.do")
    @ApiOperation("管理员用户列表")
    @ApiImplicitParams({@ApiImplicitParam(name="limit"),@ApiImplicitParam(name = "page")})
    public BaseResponse gopUserList() {
        return gopUserService.gopUserList();
    }

    @Log(title = "删除管理员", businessType = BusinessType.DELETE)
    @GetMapping("/delGopUser.do")
    @ApiOperation("删除管理员用户")
    @ApiImplicitParam(name = "id", value = "id编号")
    public BaseResponse delGopUser(Long id) {
        return gopUserService.delGopUser(id);
    }

    @GetMapping("/reviewGopUser.do")
    @ApiOperation("gop管理用用户禁用启用操作")
    @ApiImplicitParams({@ApiImplicitParam(name = "gopUserId", value = "管理员用户id"),
            @ApiImplicitParam(name = "invalid", value = "true 禁用，false 启用 ，要什么直接改")})
    public BaseResponse reviewGopUser(String gopUserId, Boolean invalid) {
        return gopUserService.reviewGopUser(gopUserId, invalid);
    }
}
